#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年2月22日

@author: Administrator
'''
from django.contrib import admin
from funcresource.models import Functional, UserFunctional, FuncResource, \
    ResourceGroup, UserResource, Resource

class ResourceAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'parent', 'url', 'remark')
    list_filter = ('state',)
    list_per_page = 50
    raw_id_fields = ('parent',)
    search_fields = ('name', 'url')
    
    
class ResourceGroupAdmin(admin.ModelAdmin):
    list_display = ('id', 'resource', 'group')
    list_filter = ('state',)
    list_per_page = 50
    raw_id_fields = ('resource', 'group')
    search_fields = ('resource__name', 'group__name')

class UserResourceAdmin(admin.ModelAdmin):
    list_display = ('id', 'user', 'resource')
    list_filter = ('state',)
    list_per_page = 50
    raw_id_fields = ('resource', 'user')
    search_fields = ('user__username', 'resource__name')
    
class FuncResourceAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'url', 'remark')
    list_filter = ('state',)
    list_per_page = 50
    search_fields = ('name', 'url')
    
class FunctionalAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'label_css', 'remark', 'func_resource')
    list_filter = ('state',)
    list_per_page = 50
    raw_id_fields = ('func_resource',)
    search_fields = ('name', 'label_css', 'func_resource__name')
    
class UserFunctionalAdmin(admin.ModelAdmin):
    list_display = ('id', 'user', 'func')
    list_filter = ('state',)
    list_per_page = 50
    raw_id_fields = ('func', 'user')
    search_fields = ('user__username', 'func__name')
    

admin.site.register(UserFunctional, UserFunctionalAdmin)
admin.site.register(Functional, FunctionalAdmin)
admin.site.register(FuncResource, FuncResourceAdmin)
admin.site.register(Resource, ResourceAdmin)
admin.site.register(ResourceGroup, ResourceGroupAdmin)
admin.site.register(UserResource, UserResourceAdmin)
